package com.gusha.service;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.gusha.dao.SysScenicDao;
import com.gusha.model.SysClassify;
import com.gusha.model.SysScenic;
import com.gusha.model.SysTicket;
import com.gusha.model.User;

@Service
@Transactional
public class SysScenicService {
	@Autowired
	private SysScenicDao sysscenicDao;
	//景点
	public Page<SysScenic> findAll(Pageable pageable, SysScenic scenic) {
	    @SuppressWarnings("serial")
	    Page<SysScenic> result = sysscenicDao.findAll(new Specification<SysScenic>() {
	        @Override
	        public Predicate toPredicate(Root<SysScenic> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
	            List<Predicate> list = new ArrayList<Predicate>();
	            if (scenic.getId() != null) {
	                list.add(cb.equal(root.get("id").as(BigInteger.class),scenic.getId()));
	            }
	            if (scenic.getScenicName() != null) {
	                list.add(cb.equal(root.get("scenicName").as(String.class),scenic.getScenicName()));
	            }
	            if (scenic.getAddName() != null) {
	                list.add(cb.equal(root.get("addName").as(String.class),scenic.getAddName()));
	            }
	            if (scenic.getAddTime() != null) {
	                list.add(cb.equal(root.get("addTime").as(Date.class),scenic.getAddTime()));
	            }
	            if (scenic.getScenicImg() != null) {
	                list.add(cb.equal(root.get("scenicImg").as(String.class),scenic.getScenicImg()));
	            }
	            if (scenic.getScenicVideo() != null) {
	                list.add(cb.equal(root.get("scenicVideo").as(String.class),scenic.getScenicVideo()));
	            }
	            if (scenic.getScenicContent() != null) {
	                list.add(cb.equal(root.get("scenicContent").as(String.class),scenic.getScenicContent()));
	            }
	            if (scenic.getIsDelete() != null) {
	                list.add(cb.equal(root.get("isDelete").as(BigInteger.class),scenic.getIsDelete()));
	            }
	            if (scenic.getIsCheck() != null) {
	                list.add(cb.equal(root.get("isCheck").as(BigInteger.class),scenic.getIsCheck()));
	            }
	            if (scenic.getScenicAddress() != null) {
	                list.add(cb.equal(root.get("scenicAddress").as(String.class),scenic.getScenicAddress()));
	            }
	            if (scenic.getChargeType() != null) {
	                list.add(cb.equal(root.get("chargeType").as(String.class),scenic.getChargeType()));
	            }
	           
	            Predicate[] p = new Predicate[list.size()];
	            return cb.and(list.toArray(p));
	        }
	    },pageable);

		return result;

	}

}
